package com.bric.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class XmlHelper {
	private static final String xmlPath = "/tables.xml";
	private static final Logger log=Logger.getLogger(XmlHelper.class);
	public static Map<String, String> getTableName() {
		SAXReader saxReader = new SAXReader();
		Map<String, String> map = null;
		Document document;
		try {
			document = saxReader.read(XmlHelper.class.getResourceAsStream(xmlPath));
			Element root = document.getRootElement();
			List<Element> tables = root.elements("table");
			if (null != tables && tables.size() > 0) {
				map = new HashMap<String, String>();
			}
			for (int i = 0; i < tables.size(); i++) {
				Element ele = tables.get(i);
				map.put(ele.attributeValue("source"), ele.getText());
			}
		} catch (Exception e) {
			log.info("解析xml出错，请检查xml"+e.getMessage());
		}
		return map;
	}

	public static void main(String[] args) {
		getTableName();
	}
}
